﻿<%@ WebHandler Language="C#" Class="treegrid" %>
using System;
using System.Web;
using System.Data.SqlClient;
using dbcaac;

public class treegrid : IHttpHandler
{
    private HttpContext context;

    public void ProcessRequest (HttpContext context) {

        this.context = context;

        // 取得页面的数据实体
        var entity = EntityFactory.getEntity(pageName);

        // 取不到实体
        if (null == entity)
        {
            ExceptionHelper.Throw404Exception(context);
        }

        // 载入表单数据
        entity.loadPageData(context);

        // 访问数据库
        SqlDataReader reader = entity.executeDataReader();

        context.Response.ContentType = "text/plain";
        var json = dbcaac.JsonHelper.GetGridTreeJSON(entity.getIdField(), entity.getPidField(), reader);
        context.Response.Write(json);
        context.Response.End();   
    } 
    
    public bool IsReusable {
        get {
            return false;
        }
    }

    protected string pageName
    {
        get { return this.context.Request["view"]; }
    }

}